package com.ts.main.admin.controller;

import com.ts.main.admin.dto.ProductDto;
import com.ts.main.admin.dto.ProductSearchPageDto;
import com.ts.main.admin.exception.R;
import com.ts.main.admin.exception.RPage;
import com.ts.main.admin.service.ProductServiceImpl;
import com.ts.main.admin.vo.ProductVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:lk
 * @Date: 2025/6/10  16:35
 */
@AllArgsConstructor
@RestController
@RequestMapping("/product")
@Tag(name = "商品管理-商品管理")
public class ProductController {
    
    private final ProductServiceImpl productServiceImpl;

    @PostMapping("/getProductPage")
    @Operation(summary = "查询商品列表（分页）")
    public RPage<List<ProductVo>> getProductPage(@RequestBody ProductSearchPageDto dto){
        return productServiceImpl.getProductPage(dto);
    }

    @GetMapping("/getProductDetails")
    @Operation(summary = "查询商品详情")
    public R<ProductVo> getProductDetails(@Schema(description = "商品ID") @RequestParam Integer productId){
        return R.ok(productServiceImpl.getProductDetails(productId));
    }

    @PostMapping("/saveProduct")
    @Operation(summary = "添加商品")
    public R<Boolean> saveProduct(@RequestBody ProductDto dto) {
        return R.ok(productServiceImpl.saveProduct(dto));
    }

    @PutMapping("/updateProduct")
    @Operation(summary = "修改商品")
    public R<Boolean> updateProduct(@RequestBody ProductDto dto) {
        return R.ok(productServiceImpl.updateProduct(dto));
    }

    @DeleteMapping("/deleteProduct")
    @Operation(summary = "删除商品")
    public R<Boolean> deleteProduct(@Schema(description = "商品ID") @RequestParam Integer productId) {
        return R.ok(productServiceImpl.deleteProduct(productId));
    }
    
}
